//
//  TWMomentsHeaderView.m
//  TWHomework-WeChat
//
//  Created by wzb on 2019/11/13.
//  Copyright © 2019 WZB. All rights reserved.
//

#import "TWMomentsHeaderView.h"
#import "Define.h"
#import "UIView+TW.h"
#import <Masonry.h>
#import "UIImageView+TW.h"
#import "TWUserInfo.h"

// 自己头像视图的宽、高
#define kMeAvatarWH             75
// 自己头像距离右边的间距
#define kMeAvatarRightMargin    10
// 封面距离底部的间距
#define kCoverImageViewBottom    20
// 头像距离名字的间距
#define kAvatarAndNameMargin    10

@interface TWMomentsHeaderView ()

// 封面
@property (nonatomic, strong) UIImageView *coverImageView;
// 当前用户头像
@property (nonatomic, strong) UIImageView *avatarImageView;
// 当前用户昵称
@property (nonatomic, strong) UILabel *nameLabel;

@end

@implementation TWMomentsHeaderView

- (instancetype)init
{
    self = [super init];
    if (self) {
        [self configUI];
    }
    return self;
}

- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        [self configUI];
    }
    return self;
}

#pragma mark - UI
- (void)configUI
{
    // 封面
    UIImageView *coverImageView = [[UIImageView alloc] init];
    coverImageView.backgroundColor = [UIColor lightGrayColor];
    [self addSubview:coverImageView];
    self.coverImageView = coverImageView;
    coverImageView.contentMode = UIViewContentModeScaleAspectFill;
    [coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.offset(0);
        make.height.equalTo(@(kCoverImageViewH));
    }];
    
    // 用户头像
    UIImageView *avatarImageView = [[UIImageView alloc] initWithFrame:CGRectMake(k_screen_width - kMeAvatarRightMargin - 85, self.coverImageView.bottom - 40, kMeAvatarWH, kMeAvatarWH)];
    avatarImageView.backgroundColor = [UIColor lightGrayColor];
    ViewRadius(avatarImageView, 4, 0, UIColor.clearColor)
    [self addSubview:avatarImageView];
    self.avatarImageView = avatarImageView;
    [avatarImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-kMeAvatarRightMargin);
        make.bottom.offset(0);
        make.width.height.equalTo(@(kMeAvatarWH));
    }];
    
    // 用户昵称
    UILabel *nameLabel = [[UILabel alloc] init];
    [self addSubview:nameLabel];
    self.nameLabel = nameLabel;
    nameLabel.textColor = [UIColor whiteColor];
    nameLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightBold];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.avatarImageView.mas_centerY);
        make.right.equalTo(self.avatarImageView.mas_left).offset(-kAvatarAndNameMargin);
    }];
}

#pragma mark - data
- (void)setUserInfo:(TWUserInfo *)userInfo
{
    _userInfo = userInfo;
    [self.coverImageView tw_setImage:userInfo.profile_image];
    [self.avatarImageView tw_setImage:userInfo.avatar];
    self.nameLabel.text = userInfo.nick;
}

@end
